package com.android.pinprovince.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.support.v4.app.Fragment;
import com.android.pinprovince.activity.BaseObject;
import com.android.pinprovince.pojo.JumpKeFuUintPojo;
import com.android.pinprovince.pojo.WidthHeighGlidePojo;

/**
 * Created by Administrator on 2017/11/14.
 */

public class CommonUtils {

    public static void JumpToKeFu(Context mcontext,JumpKeFuUintPojo pojo){
        Intent intents = new Intent(mcontext,BaseObject.class);
        intents.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"客服");

        String kf_online =  pojo.kf_online;
        String bid =  pojo.bid;
        String goods_id =  pojo.goods_id;
        if(kf_online==null) {
            String url =ConstantsUrl.basedomain+"chat?good_id=" + goods_id ;
//            String url =ConstantsUrl.basedomain+"chat?";
//            if (goods_id != null && "".equals(goods_id)) {
//
//                url+="good_id=" + goods_id ;
//            }

            if (bid != null && !bid.equals("")) {
                url+="&bid=" + bid;
                //  intents.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_WEB_URL, "http://ptmore1.lnest.cc/chat?good_id=" + goods_id + "&bid=" + bid);
            } else {
                //   intents.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_WEB_URL, "http://ptmore1.lnest.cc/chat?good_id=" + goods_id);
            }
            intents.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_WEB_URL, url);

            ReleaseManager.printLog("bottom_contact",url);
        }
        else {
            intents.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_WEB_URL,pojo.kf_online);
        }
        mcontext.startActivity(intents);
    }

    /**
     *
     * @param list_type 0表示一个的 1表示两个的?
     * @return
     */
    public static boolean  CheckLayoutStyle(int list_type){
        if(list_type==0){
            return true;
        }
        return false;
    }

    public static void SetViewWidthH(WidthHeighGlidePojo pojo, View view) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (pojo.type == 1) {
            layoutParams.width = pojo.width;
            layoutParams.height = pojo.width * 1;
            ImageView imageView = (ImageView) view;
            imageView.setLayoutParams(layoutParams);
        } else if (pojo.type == 11) {
            //1:1
            layoutParams.width = pojo.width;
            layoutParams.height = (pojo.width * 1);
            view.setLayoutParams(layoutParams);
        } else if (pojo.type == 2) {
            //750:330
            layoutParams.width = pojo.width;
            layoutParams.height = (pojo.width * 330) / 750;
            view.setLayoutParams(layoutParams);
        } else if (pojo.type == 3) {
            //750:330
            layoutParams.width = pojo.width;
            layoutParams.height = (pojo.width * 330) / 750;
            ImageView imageView = (ImageView) view;
            imageView.setLayoutParams(layoutParams);
        }
    }

    public static void LogActivityOrFragment(Object object){
        if(object instanceof Activity) {
            ReleaseManager.printLog(object.getClass().getSimpleName(), object.getClass().toString() + "---Acvitiy start");
        }else if(object instanceof Fragment) {
            ReleaseManager.printLog(object.getClass().getSimpleName(), object.getClass().toString() + "---Fragment start");
        }

    }
    public static Double StringToDouble(String str){
        Double need = Double.valueOf(str);
        return need;
    }
}
